//
//  K_LineDataModel.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/19.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "K_LineDataModel.h"

@implementation K_LineDataModel
singleton_m(K_LineDataModel)

-(NSMutableArray *)history_dataSource{
    if (!_history_dataSource) {
        _history_dataSource = [[NSMutableArray alloc]init];
    }
    return _history_dataSource;
}

-(NSMutableArray *)k_M1_dataSource{
    if (!_k_M1_dataSource) {
        _k_M1_dataSource = [[NSMutableArray alloc]init];
    }
    return _k_M1_dataSource;
}

-(NSMutableArray *)k_M5_dataSource{
    if (!_k_M5_dataSource) {
        _k_M5_dataSource = [[NSMutableArray alloc]init];
    }
    return _k_M5_dataSource;
}


#pragma mark-设置你需要增加或减少的年、月、日即可获得新的日期，上述的表示获取mydate日期前一个月的日期，如果该成+1，则是一个月以后的日期，以此类推都可以计算。
+ (NSDate *)getLaterDateFromDate:(NSDate *)date withYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = nil;
    comps = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
    NSDateComponents *adcomps = [[NSDateComponents alloc] init];
    [adcomps setYear:year];
    [adcomps setMonth:month];
    [adcomps setDay:day];
    NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:date options:0];
    return newdate;
}




#pragma mark---将NSDate-》转换成时间戳
+(NSString *)GetNSTimeIntervalWithDate:(NSDate *)date{
    NSTimeInterval time=[date timeIntervalSince1970];// 精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
//    [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
//    NSString *dateString = [dateFormatter stringFromDate:date];//将时间转化成字符串
    
    
    return timeString;
}


+(NSString *)Get_M1_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-1];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_M5_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-5];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_M15_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-15];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_M30_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-30];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_M60_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-60];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_D1_TimeInterval{
    NSDate *date = [K_LineDataModel getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-360];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

+(NSString *)Get_Now_TimeInterval{
    NSDate *date = [NSDate date];
    return [K_LineDataModel GetNSTimeIntervalWithDate:date];
}

//获取当前时间戳
+ (NSString *)currentTimeStr{
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
    NSTimeInterval time=[date timeIntervalSince1970];// 精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}

/*

NSString * t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542592861];
NSString * t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542679321];
//2018-11-19 10:01:01    2018-11-20 10:02:01


//args: {type: "kline.M1.btcusdt", from: 1542592861, to: 1542679321}
//cmd: "sub"

//from: 1542590522
//kline: []
//to: 1542591421
//ts: 1542677823
//type: "kline.M1.btcusdt"


//args: "kline.M1.btcusdt"
//cmd: "unsub"

//args: {type: "kline.M5.btcusdt", from: 1542246985, to: 1542679045}
//cmd: "sub"

NSString * M5_t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542246985];
NSString * M5_t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542679045];
//    2018-11-15 09:56:25--------2018-11-20 09:57:25
//args: "kline.M5.btcusdt"
//cmd: "unsub"

//args: {type: "kline.M15.btcusdt", from: 1541382495, to: 1542678555}
//cmd: "sub"

//from: 1541382495
//kline: [{high: "140.00000000", open: "140.00000000", low: "140.00000000", close: "140.00000000",…},…]
//to: 1542678555
//ts: 1542678496
//type: "kline.M15.btcusdt"


NSString * M15_t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1541382495];
NSString * M15_t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542678555];
//    2018-11-05 09:48:15-------2018-11-20 09:49:15
//args: "kline.M15.btcusdt"
//cmd: "unsub"
//
//args: {type: "kline.M30.btcusdt", from: 1540086648, to: 1542678708}
//cmd: "sub"
//
//
//from: 1540086648
//kline: [{high: "100.00000000", open: "100.00000000", low: "100.00000000", close: "100.00000000",…},…]
//to: 1542678708
//ts: 1542678649
//type: "kline.M30.btcusdt"


NSString * M30_t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1540086648];
NSString * M30_t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542678708];
//    2018-10-21 09:50:48  2018-11-20 09:51:48
//args: "kline.M30.btcusdt"
//cmd: "unsub"
//
//args: {type: "kline.M60.btcusdt", from: 1537494698, to: 1542678758}
//cmd: "sub"



NSString * M60_t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1537494698];
NSString * M60_t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542678758];
//    2018-09-21 09:51:38   2018-11-20 09:52:38

//args: "kline.M60.btcusdt"
//cmd: "unsub"

//
//args: {type: "kline.D1.btcusdt", from: 1511574740, to: 1542678800}
//cmd: "sub"


NSString * D1_t1 = [MOLoadHttpsData distanceTimeWithBeforeTime:1511574740];
NSString * D1_t2 = [MOLoadHttpsData distanceTimeWithBeforeTime:1542678800];
//    2017-11-25 09:52:20    2018-11-20 09:53:20

 
 */



@end
